package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDALoginRequestController {

    def commentService

    def index() {
        def result = ResultModel.getResultModel()
        try {
            def UserName = params.USERNAME ?: ""
            def Password = params.PASSWORD ?: ""
            def MACHINENAME = params.MACHINENAME ?: ""
            print MACHINENAME
            def body = [USERNAME: UserName, PASSWORD: Password]
            Header header = new Header(TRANSACTIONID: Utils.getUUID(), MESSAGENAME: "PDALoginRequest", MACHINENAME: MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header, body: body, aReturn: aReturn)
//            result = commentService.getJsonByTopic2Queue(requestModel, "sendmqname", "returnmqname", true, responseXml)
            result = commentService.getJsonByTopic2Queue(requestModel,"jms.topic.PDA.TO.CIM","jms.queue.CIM.PDA.Send",false,false)
        } catch (Exception e) {
            result.put(ResultModel.ServerErrorFlag, true)
            result.put(ResultModel.Code, ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg, ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data, e.getMessage())
            e.printStackTrace()
        } finally {
            render Utils.getFormatString(result)
        }
    }

    def responseXml = """
<MESSAGE>
<HEADER>
  <TRANSACTIONID>b4ffd66a-56ef-4faf-9670-8ff27013e371</TRANSACTIONID>
  <MESSAGENAME>PDALoginResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>2</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-05-14 10:10:36.564</EVENTTIME>
</HEADER>
<BODY>
  <WORK_NO>10014284</WORK_NO>
  <PASSWORD>123</PASSWORD>
  <NAME>崔会强</NAME>
  <ISACTIVE>true</ISACTIVE>
  <SHIFT>正常班</SHIFT>
  <EMAIL>Choi.cui@ht-tech.com</EMAIL>
  <PHONE>18393377375</PHONE>
</BODY>
<RETURN>
  <RETURNCODE>0</RETURNCODE>
  <RETURNMESSAGE>登陆成功！</RETURNMESSAGE>
</RETURN>
</MESSAGE>
    """
}
